home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 3.7 KB | 120 lines | [TEXT/GEOL] |
- Item 3399298 14-Sept-90 09:41PDT
-
- From: MUYSVASOVIC ACE - Jean-Denis Muys-Vasovic
-
- To: DK0026 DKD - Purup Electronics,IDV
- MACAPP.TECH$ MacApp Technical
-
- cc: EURO.DTS ACE - Dev Tech Supt Europe
-
- Sub: TPasswordText
-
- Peter, Dear All,
-
- Following the current thread on a password edit text, here is a solution I
- propose widely. It seems rather self-contained: the only reference in your code
- to the TPasswordText class should be to prevent linker stripping. To use it,
- you just have to specify "TPasswordText" as the TEditText class name in
- ViewEdit. The interesting piece is in IRes which calls INHERITED GetText. I
- would like to hear your comments about the validity of this heresy. At least
- SELF.GetText would be actually incorrect. Any suggestion?
-
- Create a subclass of TEditText like:
-
- TYPE
- TPasswordText = OBJECT(TEditText)
- fPassword: Str255;
- PROCEDURE TPasswordText.IPasswordText( itsSuperView : TView;
- itsLocation, itsSize: VPoint;
- itsMaxChars: INTEGER);
- PROCEDURE TPasswordText.IRes( itsDocument : TDocument;
- itsSuperView : TView; VAR itsParams : Ptr ); OVERRIDE;
- PROCEDURE TPasswordText.KeyEventToComponents(VAR info: EventInfo);
- OVERRIDE;
- PROCEDURE TPasswordText.GetText(VAR theText: Str255); OVERRIDE;
- PROCEDURE TPasswordText.SetText(VAR theText: Str255;
- redraw: BOOLEAN); OVERRIDE;
- END;
-
-
- The implementation could look like (segmentation omitted):
-
- CONST
- chObscurChar = '•'; { or '' or whatever }
- kSpaceVirtualCode = $31;
-
- PROCEDURE ObscurString(VAR S: Str255);
-
- VAR
- i: INTEGER;
-
- BEGIN
- FOR i:=1 TO Length(S) DO
- S[i] = chObscurChar;
- END;
-
- PROCEDURE TPasswordText.IPasswordText( itsSuperView : TView;
- itsLocation, itsSize: VPoint;
- itsMaxChars: INTEGER);
-
- BEGIN
- IEditText(itsSuperView, itsLocation, itsSize, itsMaxChars);
- END;
-
- PROCEDURE TPasswordText.IRes( itsDocument : TDocument; itsSuperView : TView;
- VAR itsParams : Ptr ); OVERRIDE;
-
- VAR
- temp: Str255;
-
- BEGIN
- INHERITED IRes( itsDocument, itsSuperView, itsParams );
- INHERITED GetText(temp);
- SELF.SetText(temp, kDontRedraw);
- END;
-
- PROCEDURE TPasswordText.GetText(VAR theText: Str255); OVERRIDE;
-
- BEGIN
- theText := SELF.fPassword;
- END;
-
-
- PROCEDURE TPasswordText.SetText(VAR theText: Str255;
- redraw: BOOLEAN); OVERRIDE;
-
- VAR
- temp: Str255;
-
- BEGIN
- SELF.fPassword := theText;
- temp := theText;
- ObscurString(temp);
- INHERITED SetText(temp, kDontRedraw);
- END;
-
-
- PROCEDURE TPasswordText.KeyEventToComponents(VAR info: EventInfo); OVERRIDE;
-
- BEGIN
- INHERITED KeyEventToComponents( info );
- WITH info, thePEvent^ DO
- IF (what = keyDown) | (what = autoKey) THEN
- CASE theCharacter OF
- chEnter, chReturn, chTab: { handle as usual }
- chBackSpace: { completely erase string (see HI guidelines) }
- SELF.SetText( '', kRedraw);
- OTHERWISE { just hides the character }
- BEGIN
- SELF.fPassword[0] := CHR(Length(SELF.fPassword) + 1);
- SELF.fPassword[Length(SELF.fPassword)] := theCharacter;
- theCharacter := chObscurChar;
- theKeyCode := kSpaceVirtualCode;
- message := ORD(theCharacter) + theKeyCode * 256;
- END;
- END;
- END;
-
-
-
-